/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package blink.view.task;

import java.util.Collections;
import java.util.List;
import javax.swing.AbstractListModel;

/**
 *
 * @author jerome
 */
public class GenericListModel<V> extends AbstractListModel{

    private List<V> list;
    
    public GenericListModel(List<V> list) {
        this.list=list;
    }
    
    public GenericListModel() {
        this.list=Collections.emptyList();
    }
    
    public void setList(List<V> l) {
        this.list=l;
        this.fireContentsChanged(this, 0, l.size());
    }
    
    /*protected void fireContentsChanged(int idx) {
        this.fireContentsChanged(this, idx, idx);
    }*/
    
    public void add(V e) {
        list.add(list.size(),e);
        this.fireIntervalAdded(this, list.size()-1, list.size()-1);
        
    }
    
    public void remove(int idx) {
        list.remove(idx);
        this.fireIntervalRemoved(this, idx, idx);
        
    }
    
    @Override
    public int getSize() {
        return list.size();
    }

    @Override
    public V getElementAt(int i) {
        return list.get(i);
    }
    
}
